package com.tdkj.service.shop.impl;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.shop.IBeanShopRecommendationDao;
import com.tdkj.model.shop.BeanShop;
import com.tdkj.model.shop.BeanShopRecommendation;
import com.tdkj.model.shop.BeanShopRecommendationCustom;
import com.tdkj.service.BaseService;
import com.tdkj.service.shop.IBeanShopRecommendationService;
@Component
public class BeanShopRecommendationServiceImpl extends BaseService implements
		IBeanShopRecommendationService {
	
	private IBeanShopRecommendationDao beanShopRecommendationDao;
	
	/**
	 * @param beanShopRecommendationDao the beanShopRecommendationDao to set
	 */
	@Resource
	public void setBeanShopRecommendationDao(
			IBeanShopRecommendationDao beanShopRecommendationDao) {
		this.beanShopRecommendationDao = beanShopRecommendationDao;
	}

	@Override
	public BeanShopRecommendation add(Long customId, Long shopId) {
		
		BeanShopRecommendationCustom custom = beanShopRecommendationDao.findById(customId, BeanShopRecommendationCustom.class);
		BeanShop shop = beanShopRecommendationDao.findById(customId, BeanShop.class);
		
		BeanShopRecommendation bean = new BeanShopRecommendation();
		bean.setCustom(custom);
		bean.setShop(shop);
		bean.setBuyTime(new Timestamp(System.currentTimeMillis()));
		beanShopRecommendationDao.save(bean);
		
		return bean;
	}

	@Override
	public List<BeanShopRecommendation> getAll() {
		return beanShopRecommendationDao.findAll(BeanShopRecommendation.class, "buyTime", "desc");
	}

	@Override
	public List<BeanShopRecommendation> getByCustomId(Long customId) {
		BeanShopRecommendationCustom custom = beanShopRecommendationDao.findById(customId, BeanShopRecommendationCustom.class);
		return beanShopRecommendationDao.findByProperty("custom", custom, BeanShopRecommendation.class, "buyTime", "desc");
	}

}
